import sys
input = lambda: sys.stdin.readline().rstrip("\r\n")
read_int = lambda: int(input())
read_ints = lambda: list(map(int, input().split()))
read_str = lambda: input().strip()
read_strs = lambda: read_str().split(' ')
MAX = 10 ** 6 + 1
def solve():
n = read_int()
a = read_ints()
res = MAX
a_sorted = sorted(a)
res = min(res, (a_sorted[0]+1) // 2 + (a_sorted[1]+1)//2)
for i in range(0, n-1):
b, c = a[i], a[i+1]
if b < c:
b, c = c, b
if b > 2*c:
res = min(res, (b+1) // 2)
else:
res = min(res, (b+c+2) // 3)
for i in range(0, n-2):
b, c = a[i], a[i+2]
cnt = 0
if b & 1 and c & 1:
cnt += 1
b -= 1
c -= 1
res = min(res, (b+1)//2 + (c+1)//2 + cnt)
print(res)
solve()
#include <bits/stdc++.h>
# define int long long
using namespace std;
const int cnst = 2e5+5;
// const int mod = 1e9+7;
// const int mod = 998244353;
bool mutipletestcase = false;
int dx[4] = {0, 0, -1, 1};
int dy[4] = {1, -1, 0, 0};
void output(int a) {
if(a == 1) cout << "YES" << endl;
else if(a == 0) cout << "NO" << endl;
else if(a == -1) cout << "-1" << endl;
if(mutipletestcase) return;
else exit(0);
}
int num[cnst];
bool debugging = false;
int plusone(int x) {
int a = num[x];
int b = num[x+1];
if(b > a) swap(a, b);
int y = min(a-b, b);
b -= y;
if(b == 0) return a/2+a%2;
a -= y*2;
return y+((b+a+2)/3);
}
int plustwo(int x) {
int a = num[x];
int b = num[x+2];
int min1 = min(a, b);
int diff = abs(a-b);
return min1+(diff/2+diff%2);
}
void solve() {
int n; cin >> n;
priority_queue<int, vector<int>, greater<int>> pq;
for(int i = 1; i<=n; i++) {
cin >> num[i];
pq.push(num[i]);
}
int ans = 0;
ans += pq.top()/2+pq.top()%2; pq.pop();
ans += pq.top()/2+pq.top()%2; pq.pop();
for(int i = 1; i<=n-2; i++) {
ans = min(ans, plustwo(i));
}
for(int i = 1; i<n; i++) {
ans = min(ans, plusone(i));
// cerr << num[i] << " " << num[i+1] << " " << plusone(i) << endl;
}
cout << ans << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
int t = 1;
if(mutipletestcase || debugging) cin >> t;
while(t--) solve();
}
1395A - Boboniu Likes to Color Balls | 1637C - Andrew and Stones |
1334B - Middle Class | 260C - Balls and Boxes |
1554A - Cherry | 11B - Jumping Jack |
716A - Crazy Computer | 644A - Parliament of Berland |
1657C - Bracket Sequence Deletion | 1657B - XY Sequence |
1009A - Game Shopping | 1657A - Integer Moves |
230B - T-primes | 630A - Again Twenty Five |
1234D - Distinct Characters Queries | 1183A - Nearest Interesting Number |
1009E - Intercity Travelling | 1637B - MEX and Array |
224A - Parallelepiped | 964A - Splits |
1615A - Closing The Gap | 4C - Registration System |
1321A - Contest for Robots | 1451A - Subtract or Divide |
1B - Spreadsheet | 1177A - Digits Sequence (Easy Edition) |
1579A - Casimir's String Solitaire | 287B - Pipeline |
510A - Fox And Snake | 1520B - Ordinary Numbers |